#include "../server.hpp"

void OnClosed(const PtrConnection &conn)
{
    DEBUG_LOG("OnClosed::Close Connection: %p", conn.get());
}
void OnConnected(const PtrConnection &conn)
{
    DEBUG_LOG("OnConnected::New Connection: %p", conn.get());
}
void OnMessage(const PtrConnection &conn, Buffer *buf)
{
    std::string bufstr = buf->ReadAsString(buf->ReadableSize()).c_str();
    DEBUG_LOG("%s", bufstr.c_str());
    buf->ReadMove(buf->ReadableSize());
    std::string echostr = "Server echo: " + bufstr;
    conn->Send(&echostr[0], echostr.size());
    // conn->ShutDown();
}

void t1()
{
    TcpServer server(8560);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(6);
    server.SetMessageCallback(OnMessage);
    server.SetConnectedCallback(OnConnected);
    server.SetClosedCallback(OnClosed);
    server.Start();

}


int main()
{
    t1();

    return 0;
}